<?php
class AdminDao  {
	public $table='admin';

	public  function getByNameByPassword($name,$password){
		return 	ClassManager::getSql()->onedata($this->table,'*',"where name='".$name."' and password='".md5($password)."'  and status =1 ");
	}

	public  function getByIdAndPass($id,$password){
		return 	ClassManager::getSql()->onedata($this->table,'*',"where id='".intval($id)."' and password='".$password."'  and status =1 ");
	}

	public  function getById($id){
		return 	ClassManager::getSql()->onedata($this->table,'*',"where id='".intval($id)."' ");
	}
	
	public function add($data){
		ClassManager::getSql()->insert($this->table,$data);
	}
	public function get($id){
		return ClassManager::getSql()->oneDataCache($this->table,'id', intval($id));
	}
	public function count($where){
		$where = $this->searchWhere($where);
		$count = ClassManager::getSql()->onedata1($this->table," count(*)  ",$where);
		return  $count[0];
	}
	public function getList($limit){
		return  ClassManager::getSql()->datalist($this->table,'*'," order by id desc ",$limit);
	}

	public function searchList($where=array(),$order='',$limit=0){
		$where = $this->searchWhere($where);
		return ClassManager::getSql()->dataList1($this->table,'*',$where,$order,$limit);
	}
		
	public function searchWhere($where){
		$where1 = array();
		$likeWhere = array('name');
		foreach ($where as  $k=>$v){
			if (isset($v)&&$v!==""){
				if (in_array($k,$likeWhere) ){
					$where1[$k] = array('%'.$v.'%' , 'like');
				}
				else{
					$where1[$k] = $v;
				}
			}
		}
		return $where1;
	}	
	public function deleteBatchByid($id){
		ClassManager::getSql()->delete($this->table,"where id in(".$id.")");
	}
	public function getByname($name){
		return ClassManager::getSql()->oneDataCache($this->table,'name',$name);
	}
	public function update($data,$id){
		ClassManager::getSql()->updates($this->table, $data,"where id=".intval($id));
	}
	public function updateByEmployeeId($data,$EmployeeId){
		ClassManager::getSql()->updates($this->table, $data,"where employee_id=".intval($EmployeeId));
	}
	public function updateByTeacherId($data,$teacherId){
		ClassManager::getSql()->updates($this->table, $data,"where teacher_id=".intval($teacherId));
	}
	public function updatePassword($password,$id){
		$data['password']=$password;
		ClassManager::getSql()->updates($this->table, $data,"where id=".intval($id));
	}
	public function getsByDeptId($deptId){
		return ClassManager::getSql()->datalist($this->table,'*',"where dept_id='".intval($deptId)."'");
	}
}
?>